package com.taptech.doufu.net.retrofit.api;

import com.taptech.doufu.bean.AuthorInfoBean;
import com.taptech.doufu.bean.CartoonDayBean;
import com.taptech.doufu.bean.CategoryGsonBean;
import com.taptech.doufu.bean.CategoryPlusGsonBean;
import com.taptech.doufu.bean.CollectExistGsonBean;
import com.taptech.doufu.bean.CollectUnReadBean;
import com.taptech.doufu.bean.ComicRecommendGsonBean;
import com.taptech.doufu.bean.ConfigGsonBean;
import com.taptech.doufu.bean.DFHomeBannerBean;
import com.taptech.doufu.bean.DFHomeCategoryBean;
import com.taptech.doufu.bean.DFHomeCategoryGson;
import com.taptech.doufu.bean.DynamicStatusGsonBean;
import com.taptech.doufu.bean.LimitTimeGsonBean;
import com.taptech.doufu.bean.MarketNovelNoticeBean;
import com.taptech.doufu.bean.NovelChaptersGsonBean;
import com.taptech.doufu.bean.NovelEditHistoryGsonBean;
import com.taptech.doufu.bean.NovelPublicTipsGson;
import com.taptech.doufu.bean.NovelRecommendGsonBean;
import com.taptech.doufu.bean.NovelSortDataBean;
import com.taptech.doufu.bean.NovelUploadBackupGsonBean;
import com.taptech.doufu.bean.ResponseCPLibBean;
import com.taptech.doufu.bean.ResponseMoreBannerBean;
import com.taptech.doufu.bean.RiskWordGson;
import com.taptech.doufu.bean.TagModelGsonBean;
import com.taptech.doufu.bean.TagRecommendGsonBean;
import com.taptech.doufu.bean.UserLogGsonBean;
import com.taptech.doufu.bean.appupdate.UpdateInfo;
import com.taptech.doufu.bean.base.BaseResponseBean;
import com.taptech.doufu.bean.base.BaseResponseListBean;
import com.taptech.doufu.bean.base.ResponseBaseBean;
import com.taptech.doufu.bean.cartoon.CartoonBannerGson;
import com.taptech.doufu.bean.cartoon.CartoonDetailGsonBean;
import com.taptech.doufu.bean.cartoon.CartoonReadTicketGsonBean;
import com.taptech.doufu.bean.cartoon.PayCartoonGsonBean;
import com.taptech.doufu.bean.cartoon.ResponseMoreBannerCartoonBean;
import com.taptech.doufu.bean.cp.ItemCpRankBean;
import com.taptech.doufu.bean.cp.NovelCPBanner;
import com.taptech.doufu.bean.cp.ResponseChangeHotCp;
import com.taptech.doufu.bean.cp.ResponseCpIndexDataBean;
import com.taptech.doufu.bean.cp.ResponseCpRankList;
import com.taptech.doufu.bean.novel.ChatNovelCategoryGsonBean;
import com.taptech.doufu.bean.novel.ChatNovelTopicGsonBean;
import com.taptech.doufu.bean.novel.GetVipTicketGsonBean;
import com.taptech.doufu.bean.novel.ImageGsonBean;
import com.taptech.doufu.bean.novel.NovelPayInfoGsonBean;
import com.taptech.doufu.bean.novel.NovelRankItemSortBean;
import com.taptech.doufu.bean.novel.NovelShowADInfoGsonBean;
import com.taptech.doufu.bean.novel.NovelSubGsonBean;
import com.taptech.doufu.bean.novel.PersonalLikeGsonBean;
import com.taptech.doufu.bean.novel.VipTopicGsonBean;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.model.novel.bean.NovelAttentionBean;
import com.taptech.doufu.model.novel.bean.NovelBookListGson;
import com.taptech.doufu.model.novel.bean.NovelBuyBean;
import com.taptech.doufu.model.novel.bean.NovelCategoryGroupGson;
import com.taptech.doufu.model.novel.bean.NovelChapterListGson;
import com.taptech.doufu.model.novel.bean.NovelPraiseCommentBean;
import com.taptech.doufu.model.novel.bean.NovelRecommendGson;
import com.taptech.doufu.model.novel.bean.NovelSettingReviewBeanGson;
import com.taptech.doufu.model.novel.bean.NovelShareRankGson;
import com.taptech.doufu.model.novel.bean.NovelCategoryGson;
import com.taptech.doufu.model.novel.gson.NovelDetailGson;
import com.taptech.doufu.model.user.UserDetailBean;
import com.taptech.doufu.model.user.UserPosterBean;
import com.taptech.doufu.services.history.ReadRecordGson;

import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;
import retrofit2.http.Streaming;
import retrofit2.http.Url;
import rx.Observable;

/**
 * api
 */
public interface ApiServer {

    String BASE_URL = Constant.HOST_NAME_SECOND;
    String CACHE_KEY = "DoufuCache";//自定义缓存设置KEY
    String CACHE = "DoufuCache:";//自定义缓存设置字段

    //同人
    @GET("/index.php/cp/cp_data")
    Observable<ResponseCPLibBean> getCPLibListResponse();

    //同人-征文活动-热门作品等
    @Headers(CACHE +(60*60*24))
    @GET("/index.php/new_home/new_fanfiction/recommend?type=1")
    Observable<ResponseCpIndexDataBean> getCpIndexData();

    //同人-热门CP-标签
    @GET("/index.php/topics/cp_info?id=1403")
    Observable<ResponseChangeHotCp> getChangeHotCpTag(@Query("last") String last);
    //同人-轮播图
    @Headers(CACHE +(60*60*24))
    @GET("/index.php/cp/banner/")
    Observable<BaseResponseBean<NovelCPBanner>> getNovelCPBanner();

    //同人-分类
    @Headers(CACHE + (60*60*24))
    @GET("/index.php/entrance_item/cp/")
    Observable<BaseResponseBean<List<DFHomeCategoryBean>>> getNovelCpCategory(@Query("sexType") String sexType);
    //小喇叭
    @Headers(CACHE + (60*60*24))
    @GET("/index.php/entrance_item/bbs/")
    Observable<BaseResponseListBean<MarketNovelNoticeBean>> getNovelSpeaker(@Query("sexType") String sexType);


    //漫画轮播图
    @GET("/index.php/banner/get/")
    Observable<CartoonBannerGson> getCartoonBanner(@Query("place") String place);

    //更多分类
    @Headers(CACHE + (60*60*24))
    @GET
    Observable<ResponseMoreBannerBean> getMoreBanner(@Url String url);

    @GET
    Observable<BaseResponseBean<DFHomeCategoryGson>> getChoiceCategoryDetail(@Url String url);

    //彩虹/言情 轮播图
    @Headers(CACHE +(60*60*24))
    @GET
    Observable<BaseResponseBean<List<DFHomeBannerBean>>> getNovelBanner(@Url String url);


    //白鲸对话小说轮播图
    @GET("/index.php/banner/get?place=chatnovel.index")
    Observable<BaseResponseBean<List<DFHomeBannerBean>>> getChatNovelBanner();


    //包月专区轮播图
    @GET("/banner/get?place=vip.block")
    Observable<BaseResponseBean<List<DFHomeBannerBean>>> getVipBanner();


    @GET("/banner/get?place=select.index")
    Observable<BaseResponseBean<List<DFHomeBannerBean>>> getChoiceBanner();

    //彩虹/言情 分类
    @Headers(CACHE + (60*60*24))
    @GET
    Observable<BaseResponseBean<List<DFHomeCategoryBean>>> getNovelCategory(@Url String url);

    @GET
    Observable<BaseResponseBean<NovelCategoryGroupGson>> getNovelCategoryGroupByUrl(@Url String url);


    @GET
    Observable<BaseResponseBean<NovelCategoryGson>> getNovelCategoryList(@Url String url, @Query("last") int last,@Query("data") String data,@Query("sub_tag") String tag);


    @Headers(CACHE + (60*60*24))
    @GET("/new_home/new_home/entrance?type=select")
    Observable<BaseResponseBean<List<DFHomeCategoryBean>>> getChoiceCategory();

    @GET("/chatnovel/entrance")
    Observable<ChatNovelCategoryGsonBean> getChatNovelCategory();

    //彩虹/言情/TOPIC
    @Headers(CACHE + (60*60*24))
    @GET
    Observable<ResponseCpIndexDataBean> getNovelTopic(@Url String url);


    @GET("/select/home")
    Call<ResponseBody> getChoiceTopic(@Query("young") int young);

    @GET("/chatnovel/blocks")
    Observable<ChatNovelTopicGsonBean> getChatNovelTopic(@Query("firstLoad") int firstLoad);


    @GET("/vip/vipBlocks")
    Call<ResponseBody> getVipTopic();


    @GET("/vip/vipState")
    Call<ResponseBody> getVipState();
    

    //彩虹/言情/个人喜欢
    @Headers(CACHE + (60*60*24))
    @GET("/index.php/novel/personal_recommend/")
    Observable<PersonalLikeGsonBean> getNovelPersonalLike(@Query("sexType") String sexType, @Query("last") String last);

    //同人的订阅
    @Headers(CACHE + (60*60*24))
    @GET("/index.php/search/cps/")
    Observable<NovelSubGsonBean> getNovelSub(@Query("last") String last,@Query("types") int types,@Query("size") int size);

    @GET
    Observable<ResponseMoreBannerCartoonBean> getMoreBannerCartoon(@Url String url);

    @GET("/index.php/cp/category/")
    Observable<ItemCpRankBean> getCpRankBean();

    //获取分类数据
    @GET
    Observable<CategoryGsonBean> getCategoryData(@Url String url);

    @GET
    Observable<CategoryPlusGsonBean> getCategoryPlusData(@Url String url);


    @GET
    Observable<VipTopicGsonBean> getVipTopic(@Url String url);


    @GET
    Observable<ImageGsonBean> getImageData(@Url String url);

    //获取限时打折的数据
    @GET
    Observable<LimitTimeGsonBean> getLimitTimeData(@Url String url);

    @Headers(CACHE + 200)
    @GET
    Observable<ResponseCpRankList> getCpRankList(@Url String url);

    @GET("/index.php/comics/comics_entrance?old=1&")
    Observable<ResponseCpIndexDataBean> getCartoonIndexList();


    @GET("/index.php/apk/info/get")
    Observable<UpdateInfo> getUpdateInfo(@Query("apk_version_name") String version_name,
                                         @Query("apk_version_code") int apk_version_code,
                                         @Query("user_id") String user_id,
                                         @Query("apk_device_info") String apk_device_info,
                                         @Query("sdk_version") int sdk_version);
    @Streaming
    @GET()
    Observable<Response<ResponseBody>>  getUpdateApkFile(@Url String url);


    @Headers(CACHE + 200)
    @GET("/index.php/entrance_item/rank_list")
    Observable<NovelRankItemSortBean> getNovelRankItemSort(@Query("sexType") String sex_type,@Query("version") int version);

    @Headers(CACHE + 200)
    @GET
    Observable<NovelRankItemSortBean> getNovelRankItemSort(@Url String url);

    //小说筛选
    @GET("/index.php/albums/search_rule_info")
    Observable<NovelSortDataBean> getNovelSortDataBean();



    //
    @Headers(CACHE + 200)
    @GET("/index.php/comics/recent")
    Observable<CartoonDayBean> cartoonTips(@Query("last") String last,
                                                             @Query("size") int size,
                                                             @Query("transfered") int transfered);

    /**
     * 获取漫画目录
     * @param id
     * @return
     */
    @GET("/comics/all_chapter")
    Observable<CartoonDetailGsonBean> getCartoonAllChapters(@Query("id") String id);


    /**
     * 获取漫画所有详细数据
     * @param id
     * @return
     */
    @GET("/comics/detail")
    Observable<CartoonDetailGsonBean> getCartoonAllDetail(@Query("id") String id);

    @GET("/getMyComicReadTicketId")
    Observable<CartoonReadTicketGsonBean> getCartoonReadTicket(@Query("comic_id") String id);


    /**
     * 统计漫画阅读数
     * @param id
     * @return
     */
    @FormUrlEncoded
    @POST("/journals/stat_read")
    Observable<ResponseBaseBean> statRead(@Field("id") String id);




    @FormUrlEncoded
    @POST("/Dynamic/setStatus")
    Observable<DynamicStatusGsonBean> setDynamicStatus(@Field("status") int status);

    /**
     * 取消未读
     * @param id
     * @param object_type
     * @return
     */
    @FormUrlEncoded
    @POST("/Collect/cancelReadMark")
    Observable<ResponseBaseBean> cancelReadMark(@Field("id") String id,@Field("object_type") int object_type);


    @FormUrlEncoded
    @POST("/Comic/Buy")
    Observable<PayCartoonGsonBean> payCartoon(@Field("comic_id") String comic_id,
                                              @Field("chapter_id") String chapter_id,
                                              @Field("auto_pay") String flag,
                                              @Field("read_ticket_id") String ticketId);

    /**
     * 判断是否收藏某作品
     * @param id
     * @param object_type
     * @return
     */
    @GET("/favorite/has_add")
    Observable<CollectExistGsonBean> judgeCollectExist(@Query("id") String id,
                                                       @Query("object_type") String object_type);


    /**
     * 取消收藏
     * @param id
     * @param object_type
     * @return
     */
    @FormUrlEncoded
    @POST("/favorite/remove")
    Observable<ResponseBaseBean> removeCollect(@Field("id") String id,
                                               @Field("object_type") String object_type);


    /**
     * 将本地的阅读记录同步到服务器
     * @param data
     * @return
     */
    @FormUrlEncoded
    @POST("/readHistory/moveData")
    Observable<ResponseBaseBean> moveReadHistory(@Field("data") String data,@Field("force") int force);

    @FormUrlEncoded
    @POST("/readHistory/addOrUpdateData")
    Observable<ResponseBaseBean> addOrUpdateDataReadHistory(@Field("novel_id") String novel_id,
                                                @Field("section_id") String section_id,
                                                @Field("position") int position,
                                                @Field("name") String name,
                                                @Field("img_url") String img_url,
                                                @Field("progress") String progress,
                                                @Field("all_num") int all_num,
                                                @Field("type") int type);



    @FormUrlEncoded
    @POST("/readHistory/deleteData")
    Observable<ResponseBaseBean> deleteReadHistoryData(@Field("novel_id") String data, @Field("type") int type);


    @POST("/readHistory/deleteAllData")
    Observable<ResponseBaseBean> deleteReadHistoryAllData();

    @GET("/readHistory/getReadHistory")
    Observable<ReadRecordGson> getReadHistory(@Query("size") int size,@Query("last") int last);


    @GET("/readHistory/getBookshelfData")
    Observable<ReadRecordGson> getBookshelfData();



    @GET("/readHistory/getInfo")
    Observable<ReadRecordGson> getInfo(@Query("novel_id") String novel_id,@Query("type") int type);

    /**
     * 收藏
     * @param id
     * @param object_type
     * @return
     */
    @FormUrlEncoded
    @POST("/favorite/add")
    Observable<ResponseBaseBean> addCollect(@Field("id") String id,
                                               @Field("object_type") String object_type);


    @GET("/vip/getVipFreeTicket")
    Observable<GetVipTicketGsonBean> getVipTicket(@Query("object_id") int object_id,@Query("object_type") int object_type);

    /**
     * 获取小说购买的信息
     * @param id
     * @return
     */
    @GET("/Novel/BuyInfo")
    Observable<NovelPayInfoGsonBean> getNovelPayInfo(@Query("novel_id") String id);



    /**
     * 获取小说广告显示的信息
     * @param id
     * @return
     */
    @GET("/Novel/getShowADInfo")
    Observable<NovelShowADInfoGsonBean> getNovelShowADInfo(@Query("novel_id") String id);

    /**
     * 获取收藏作品的未读个数
     * @return
     */
    @GET("/favorite/collect_updated_count")
    Observable<CollectUnReadBean> getCollectUnRead();


    /**
     * 获取标签，包括官方标签和自定义标签
     * @param sexuality
     * @param topic_id
     * @return
     */
    @GET("/novelTag/getGovernmentTags")
    Observable<TagModelGsonBean> getGovernmentTags(@Query("sexuality") int sexuality, @Query("topic_id") String topic_id);


    /**
     * 获取推荐标签
     * @param sexuality
     * @param key
     * @return
     */
    @GET("/novelTag/getRecommendTags")
    Observable<TagRecommendGsonBean> getRecommendTags(@Query("sexuality") int sexuality, @Query("key") String key,@Query("single_page")int single_page);


    /**
     * 获取推荐的漫画数据
     * @return
     */
    @GET("/Search/HotComics")
    Observable<ComicRecommendGsonBean> getComicRecommendInSearch();


    /**
     * 获取推荐的小说数据
     * @return
     */
    @GET("/search/get_popular_keywords_plus")
    Observable<NovelRecommendGsonBean> getNovelRecommendInSearch(@Query("type") int type,@Query("single_page") int single_page, @Query("size") int size);




    /**
     * 获取自己所有的小说及其章节的ID集合
     * @return
     */
    @GET("/Novel/getAllNovelsByUid")
    Observable<NovelChaptersGsonBean> getAllNovelsByUid();


    /**
     * 上传所有的本地备份
     * @param array
     * @return
     */
    @FormUrlEncoded
    @POST("/Novel/uploadMyAllBackUp")
    Observable<NovelUploadBackupGsonBean> uploadMyAllBackUp(@Field("array") String array);


    /**
     * 上传单个备份
     * @param data
     * @return
     */
    @FormUrlEncoded
    @POST("/Novel/uploadMySingleBackUp")
    Observable<ResponseBaseBean> uploadMySingleBackUp(@Field("data") String data);


    /**
     * 历史备份恢复
     * @param data
     * @return
     */
    @FormUrlEncoded
    @POST("/Novel/resetBackUp")
    Observable<ResponseBaseBean> resetBackUp(@Field("data") String data,
                                             @Field("backup_id") long backupID);

    @FormUrlEncoded
    @POST("/data/upload")
    Observable<UserLogGsonBean> uploadUserLog(@Field("info") String data);


    /**
     * 获取小说编辑的历史数据
     * @param novel_id
     * @param chapterID
     * @return
     */
    @GET("/Novel/getNovelBackUps")
    Observable<NovelEditHistoryGsonBean> getNovelEditHistory(@Query("novel_id") String novel_id,@Query("chapter_id") String  chapterID);


    /**
     * 获取后台配置的信息
     * @param device_id
     * @param simulator
     * @return
     */
    @GET("/config/getGlobalConfig")
    Observable<ConfigGsonBean> getGlobalConfig(@Query("device_id") String device_id, @Query("simulator") int  simulator);


    /**
     *发布小说页面的提示文案
     */
    @GET("/index.php/member/prompt")
    Observable<NovelPublicTipsGson> getNovelPublishTips(@Query("object_type") int objectType);


    @FormUrlEncoded
    @POST("/authorInfo/setAuthorInfo")
    Observable<BaseResponseBean<AuthorInfoBean>> setAuthorInfo(@Field("info") String info);

    /**
     * 获取敏感词库
     * @return
     */
    @GET("/writing/risk_words")
    Observable<RiskWordGson> getRiskWords();


    /**
     * 获取小说详情数据
     * @param novelId
     * @return
     */
    @GET("/topic/novel")
    Observable<BaseResponseBean<NovelDetailGson>> getNovelDetails(@Query("topic_id") int novelId);


    @GET("/topic/novel")
    Observable<BaseResponseBean<NovelDetailGson>> getNovelDetails(@Query("topic_id") int novelId,@Query("keyword") String keyword);

    @GET("/user/author/info")
    Observable<BaseResponseBean<UserDetailBean>> getUserDetail(@Query("user_id") int uid);

    @GET("/user/author/novels")
    Observable<BaseResponseBean<UserDetailBean>> getUserNovelList(@Query("user_id") int uid);

    @GET("/user/author/poster")
    Observable<BaseResponseBean<UserPosterBean>> getUserPoster(@Query("user_id") int uid);

    /**
     * 获取分享小说的用户列表
     */
    @GET("/sharerecords/get_shares")
    Observable<BaseResponseBean<NovelShareRankGson>> getNovelShareRank(@Query("object_id") int novelId);


    /**
     * 根据小说/作者获取推荐小说
     */
    @GET("/relating/relating_novel")
    Observable<BaseResponseBean<NovelRecommendGson>> getNovelRecommend(@Query("user_id") int uid, @Query("novel_id") int novelId, @Query("size") int size, @Query("begin") int begin);

    /**
     * 根据小说/作者推荐书单
     */
    @GET("/Booklist/Related")
    Observable<BaseResponseBean<NovelBookListGson>> getNovelBookList(@Query("novel_id") int novelId);


    @FormUrlEncoded
    @POST("/user/msg_center/user_attracted")
    Observable<BaseResponseBean<NovelAttentionBean>> attentionUser(@Field("attention_user_uid") int uid);


    @FormUrlEncoded
    @POST("/user/msg_center/cancel_attracted")
    Observable<BaseResponseBean<String>> cancelAttentionUser(@Field("attention_user_uid") int uid);


    @FormUrlEncoded
    @POST("/new_comment/novel_comment/comment_like")
    Observable<BaseResponseBean<NovelPraiseCommentBean>> praiseComment(@Field("id") int id);



    @FormUrlEncoded
    @POST("/new_comment/novel_comment/comment_unlike")
    Observable<BaseResponseBean<NovelPraiseCommentBean>> cancelPraiseComment(@Field("id") int id);

    @FormUrlEncoded
    @POST("/favorite/add")
    Observable<BaseResponseBean> collectNovel(@Field("uid") int uid, @Field("object_type") int objectType, @Field("id") int id);


    @FormUrlEncoded
    @POST("/favorite/remove")
    Observable<BaseResponseBean> cancelCollectNovel(@Field("uid") int uid, @Field("object_type") int objectType, @Field("id") int id);

    @GET("/novel/chapter_list")
    Observable<BaseResponseBean<NovelChapterListGson>> getNovelChapterList(@Query("novel_id") int novelId);

    @FormUrlEncoded
    @POST("/Novel/BatchBuy")
    Observable<BaseResponseBean<NovelBuyBean>> buyAllChapter(@Field("novel_id") int novelId, @Field("object_type") int objectType);

    @FormUrlEncoded
    @POST("/full_buy/buy")
    Observable<BaseResponseBean<NovelBuyBean>> buyTheBook(@Field("object_id") int novelId, @Field("object_type") int objectType);


    @GET("/novel/auditing_info")
    Observable<BaseResponseBean<NovelSettingReviewBeanGson>> getNovelSettingReview(@Query("novel_id") int novel_id);

}
